package controller;

import gui.Main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

/**
 * @author hqthai01 Jan 2, 2015
 */
public class BtnCertificateBrowseAction implements ActionListener {

	private Main gui;
	private JFileChooser chooser;

	public BtnCertificateBrowseAction(Main gui) {
		this.gui = gui;
		chooser = new JFileChooser();
		chooser.setFileFilter(new FileFilter() {
			
			@Override
			public String getDescription() {
				return "Certificate file only (*.crt)";
			}
			
			@Override
			public boolean accept(File f) {
				if(f.isDirectory())
					return true;
				return f.getName().endsWith(".crt");
			}
		});
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		int choice = chooser.showOpenDialog(gui);
		if(choice == JFileChooser.APPROVE_OPTION){
			gui.getTfCertificate().setText(chooser.getSelectedFile().getAbsolutePath());
		}
	}
}
